<div id="admin" style="width: 100%;height: 100%;">

					<div class="panel panel-default">
						<div class="panel-heading">
							管理员列表
						</div>

						<div class="navbar-form navbar-left" role="search">
							<div class="form-group">
								<input type="text" id="s_acount" class="form-control" placeholder="请输入管理员账号">
								<input type="text" id="s_userName" class="form-control" placeholder="请输入姓名">
							</div>
							 <button type="button" onclick="ready('','');" style="" class="btn btn-default">搜索</button>
                             <button onclick="closeWindow();" class="btn btn-success" id="btn_add" data-toggle="modal"><i class="glyphicon glyphicon-plus"></i>&nbsp;新增</button>
						</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<div class="table-responsive" style="height:600px;">
								<table class="table">
									<thead>
										<tr>
											<th>#</th>
											<th>名称</th>
											<th>电话号码</th>
											<th>账号</th>
											<th>状态</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="admin_tbody">
									
									</tbody>
								</table>
							</div>
							<!-- /.table-responsive -->
						</div>
						<!-- /.panel-body -->
					</div>

					 <div style="text-align:right">
	                    <span style="margin-right:30px;">当前是：01页</span>
	                    <ul class="pagination pagination-sm" id="paging" style="vertical-align:middle;">
						<li><a href="#">&laquo;</a></li>
						<li><a href="#">1</a></li>
						<li><a href="#">2</a></li>
						<li><a href="#">3</a></li>
						<li><a href="#">4</a></li>
						<li><a href="#">5</a></li>
						<li><a href="#">&raquo;</a></li>
				       </ul>
                    </div>
					
					
					
					
					<div class='pop' id="pop">
						<div class='box'>
							<div class="modal-header">
									添加任务
									<button type="button" onclick="closeWindow();" class="close" data-dismiss="modal" aria-hidden="true">×</button>
									<h4 class="modal-title" id="myModalLabel"></h4>
								</div>
								<div>
										<div class="form-group pad0-30" align="center">
											<label for="firstname" >用户名称</label>
											<input type="text" class="form-control" id="userName" placeholder="请输入用户名称"><span id="userNameErr" style="color: red"></span>
										</div>
										<div class="form-group pad0-30" align="center">
											<label for="lastname" >用户电话</label>
											<input type="text" class="form-control" id="phone" placeholder="请输入用户电话"><span id="phoneErr" style="color: red"></span>
										</div>
										<div class="form-group pad0-30" align="center">
											<label for="lastname" >登录账号</label>
											<input type="text" class="form-control" id="account" placeholder="请输入登录账号"><span id="accountErr" style="color: red"></span>
										</div>
										<div class="form-group pad0-30" align="center">
											<label for="lastname" >登录密码</label>
											<input type="text" class="form-control" id="password" placeholder="请输入登录密码"><span id="passwordErr" style="color: red"></span>
										</div>
										<div class="form-group pad0-30" align="center">
											<label for="lastname" >账号状态</label>
											<select class="form-control" id="state">
												<option value="1">启用</option>
												<option value="0">禁用</option>
											</select>
										</div>
									<div align="center" id="errInput" style="color: red;"></div>
								</div>
								<div class="modal-footer">
									<button id="closeW" type="button" class="btn btn-default" onclick="closeWindow();">关闭</button>
									<button type="button" id="submit" onclick="addAdmin();" class="btn btn-primary">提交</button>
								</div>
							</div>
							
						</div>
						
						
						
						<div class='pop' id="passwd">
						<div class='box'>
							<div class="modal-header">
									修改密码
									<button type="button" onclick="closeWindowPassword();" class="close" data-dismiss="modal" aria-hidden="true">×</button>
									<h4 class="modal-title" id="myModalLabel"></h4>
								</div>
								<div>	
										<div class="form-group pad0-30" align="center">
											<label for="firstname" >请输入原密码</label>
											<input type="text" class="form-control" id="password0" placeholder="请输入原密码"><span id="password0Err" style="color: red"></span>
										</div>
										<div class="form-group pad0-30" align="center">
											<label for="firstname" >请输入新密码</label>
											<input type="text" class="form-control" id="password1" placeholder="请输入新密码"><span id="password1Err" style="color: red"></span>
										</div>
										<div class="form-group pad0-30" align="center">
											<label for="firstname" >请再次输入密码</label>
											<input type="text" class="form-control" id="password2" placeholder="请再次输入新密码"><span id="password2Err" style="color: red"></span>
										</div>
								</div>
								<div class="modal-footer">
									<button id="closeWs" type="button" class="btn btn-default" onclick="closeWindowPassword();">关闭</button>
									<button type="button" id="submit" onclick="updatePassword();" class="btn btn-primary">提交</button>
								</div>
							</div>
							
						</div>
					</div>
					

<script type="text/javascript">

	//页面加载执行数据渲染	
	$(function(){ 
		ready("","");
	}); 
	
	
	//界面加载方法
	function ready(currentPageNum,totle){
		
		// 分页参数设定
		if(currentPageNum=="" || currentPageNum==null){
			currentPageNum=1;
		}
		
		// 分页参数设定
		if(totle=="" || totle==null){
			totle=10;
		}
		
		var userName=$("#s_userName").val();
		var account=$("#s_acount").val();
		
		var data={'currentPageNum':currentPageNum,'perPageSize':totle,'userName':userName,'account':account};
		$.ajax({  
		    type:'post',    
		    url:'/Admin/selectAll.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
				console.log(data);		    	
		    	Data_assembly(data);
		    	footer(data.data.totalPageNum,data.data.currentPageNum);
		    }  
		  });
	}
	
	//数据组装方法
	function Data_assembly(data){
		  console.log(data);
		  console.log(tbody);
		  var tbody=data.data.entitys;
		  var html="";
		  var b=1;
		  for(var i=0;i<tbody.length;i++){
			  html+='<tr>';
			  html+='<td>'+b+'</td>';
			  html+='<td>'+tbody[i].userName+'</td>';
			  html+='<td>'+tbody[i].phone+'</td>';
			  html+='<td>'+tbody[i].account+'</td>';
			  if(tbody[i].state==1){
				  html+='<td>启用</td>';
			  }else{
				  html+='<td>禁用</td>';
			  }
			  
			 // html+='<td>'+tbody[i].state+'</td>';
			  html+='<td><button type="button" onclick="updateSelect('+"'"+tbody[i].id+"'"+');" class="btn btn-warning">修改密码</button>&nbsp;&nbsp;'
				  +'<button type="button" onclick="deleteAdmin('+"'"+tbody[i].id+"'"+');" class="btn btn-danger">删除</button>&nbsp;&nbsp;';
			  
			    
			  if(tbody[i].state==0){
				  html+='<button type="button" onclick="upAdmin('+"'"+tbody[i].account+"'"+');" class="btn btn-success">启用</button></td>';
			  }
			  html+='</td></tr>';
		  }
		  
		  $("#admin_tbody").html(html);
	}
	
	
	//修改密码
	function updateSelect(id){
		
		var data={"id":id};
		$.ajax({  
		    type:'post',    
		    url:'/Login/checkAcount.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
				if(data==0){
					alert("没有修改此密码的权限");
					return;
				}else if(data==1){
					closeWindowPassword();
				}else{
					alert("系统错误");
				}
		    }  
		  });
	}
	
	//添加用户
	function addAdmin(){
		var userName=$("#userName").val();
		var phone=$("#phone").val();
		var account=$("#account").val();
		var state=$("#state").val();
		var password=$("#password").val();
		var errText="";
		var errCode="0";
		//数据校验
		if(userName==null || userName=='' || userName.length>10){
			  $("#userNameErr").html("用户名不能为空,且长度不能超过十个字段");
			  errCode="1";
		}else{
			 $("#userNameErr").html("");
		}
		
		//数据校验
		if(phone==null || phone=='' || phone.length>20){
			  $("#phoneErr").html("用户名不能为空,且长度不能超过二十个字段");
			  errCode="1";
		}else{
			 $("#phoneErr").html("");
		}
		
		//数据校验
		if(account==null || account=='' || account.length>20){
			  $("#accountErr").html("用户名不能为空,且长度不能超过二十个字段");
			  errCode="1";
		}else{
			 $("#accountErr").html("");
		}
		
		//数据校验
		if(password==null || password=='' || password.length>20){
			  $("#passwordErr").html("用户名不能为空,且长度不能超过二十个字段");
			  errCode="1";
		}else{
			 $("#passwordErr").html("");
		}
		
		if(errCode=="1"){
			return;
		}
				
		var data={'userName':userName,'phone':phone,'account':account,'state':state,'password':password};	
		$.ajax({  
		    type:'post',    
		    url:'/Admin/insert.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){
		    	if(data.code==0){
		    		alert(data.msg);
		    		ready("","");
			    	closeWindow();
			    	return;
		    	}else{
		    		alert(data.msg);
		    		return;
		    	}
		    	
		    	
		    	
		    }  
		  });
	
	}
	
	//删除
	function deleteAdmin(id){
		
		
		if(id==null || id==''){
			return;
		}
		
		if (confirm("确认删除吗?")==true){
			}else{
			return;
		}
		
		var data={'id':id};
		$.ajax({  
		    type:'post',    
		    url:'/Admin/deleteByPrimaryKey.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){  
		    	alert(data.msg);
		    	ready("","");
		    }  
		  });
	}
	
	 //启用
	function upAdmin(id){
	 var data={'account':id};
		$.ajax({  
		    type:'post',    
		    url:'/Login/upAdmin.do',  
		    data:data,  
		    cache:false,  
		    dataType:'text',  
		    success:function(data){  
		    	alert(data);
		    	ready("","");
		    }  
		  });
	}

	 
	 //修改密码
	 function updatePassword(){
		 
		 var password_j=$("#password0").val();
		 var password_1=$("#password1").val();
		 var password_2=$("#password2").val();
		 var errCode=0;
		//数据校验
		if(password_j==null || password_j=='' || password_j.length>20){
			  $("#password0Err").html("旧不能为空,且长度不能超过二十个字段");
			  errCode="1";
		}else{
			 $("#password0Err").html("");
		}
		
		//数据校验
		if(password_1==null || password_1=='' || password_1.length>20){
			  $("#password1Err").html("新密码不能为空,且长度不能超过十个字段");
			  errCode="1";
		}else{
			 $("#password1Err").html("");
		}
		//数据校验
		if(password_2==null || password_2=='' || password_2.length>20){
			  $("#password2Err").html("新密码不能为空,且长度不能超过十个字段");
			  errCode="1";
		}else{
			 $("#password2Err").html("");
		}
		
		if(errCode==1){
			return;
		}
		
		if(password_1!=password_2){
			 $("#password1Err").html("新密码两次输入不一致");
			return;
		}else{
			$("#password1Err").html("");
		}
		
		 var data={'password':password_1,'password_j':password_j};
			$.ajax({  
			    type:'post',    
			    url:'/Login/updatePassword.do',  
			    data:data,  
			    cache:false,  
			    dataType:'text',  
			    success:function(msg){
			    	if(JSON.parse(msg).code==0){
			    		alert(JSON.parse(msg).msg);
			    		closeWindowPassword();
			    		return;
			    	}else{
			    		alert(JSON.parse(msg).msg);
			    		return;
			    	}
			    }  
			  });
		 
	 }
	 
	//关闭弹出层
	function closeWindow(){
		$("#pop").fadeToggle();
	}
	//关闭弹出层
	function closeWindowPassword(){
		 $("#password0").val("");
		 $("#password1").val("");
		 $("#password2").val("");
		$("#passwd").fadeToggle();
	}
	
	
	//分页页脚生成方法
	//dataSize 总页数
	//unmSize 当前所在页数
	function footer(dataSize, unmSize) {
		$("#paging").find("li").remove();
		var html = '<li><a href="javascript:skip(1,' + unmSize + ',' + dataSize
				+ ');">&laquo;</a></li>';
		$("#paging").append(html);

		var number = 12;

		// 判断生成前面部分页脚
		if (unmSize > 5) {
			html = '<li><a href="javascript:skip(0,1);">1</a></li>';
			$("#paging").append(html);
			html = '<li><a href="javascript:skip(0,2);">2</a></li>';
			$("#paging").append(html);
			html = '<li><a href="javascript:void(0);">...</a></li>';
			$("#paging").append(html);
			number = number - 3;
			// 循环生成前半部分
			for (var i = 3; i > 0; i--) {
				if (unmSize - 2 - i > 3) {
					for (i; i > 0; i--) {
						number--;
						var finlSize = unmSize;
						finlSize = finlSize - i;
						html = '<li><a href="javascript:skip(0,' + finlSize + ','
								+ dataSize + ');">' + finlSize + '</a></li>';
						$("#paging").append(html);
					}
					break;
				}
			}

		} else {
			for (var i = 1; i < unmSize; i++) {
				number--;
				html = '<li><a href="javascript:skip(0,' + i + ',' + dataSize
						+ ');">' + i + '</a></li>';
				$("#paging").append(html);
			}
		}

		// 生成当前页
		html = '<li><a style="color:#000;" href="javascript:skip(0,' + unmSize
				+ ',' + dataSize + ');">' + unmSize + '</a></li>';
		$("#paging").append(html);

		// 循环生成后半部分
		for (var i = number; i > 0; i--) {

			if (unmSize + i <= dataSize) {
				number = i;
				var size = unmSize;
				for (i; i > 0; i--) {
					size = size + 1;
					html = '<li><a href="javascript:skip(0,' + size + ','
							+ dataSize + ');">' + size + '</a></li>';
					$("#paging").append(html);
				}
			}
		}

		// 判断生成最后部分页脚
		var endNumber = dataSize - unmSize - number;
		if (endNumber > 3) {
			// 尾部长度超出三个，用省略号代替
			html = '<li><a href="javascript:void(0);">...</a></li>';
			$("#paging").append(html);
			var endSize = dataSize - 1;
			html = '<li><a href="javascript:skip(0,' + endSize + ');">' + endSize
					+ '</a></li>';
			$("#paging").append(html);
			html = '<li><a href="javascript:skip(0,' + dataSize + ');">' + dataSize
					+ '</a></li>';
			$("#paging").append(html);

		} else {
			// 尾部长度没有超出三个，不用省略号
			for (var i = endNumber; i > 0; i--) {
				html = '<li><a href="javascript:skip(0,' + dataSize + ');">'
						+ dataSize + '</a></li>';
				$("#paging").append(html);
				dataSize = dataSize - i;
			}
		}
		html = '<li><a href="javascript:skip(2,' + unmSize + ',' + dataSize
				+ ');">&raquo;</a></li>';
		$("#paging").append(html);
	}



	//分页前置配参执行方法
	function skip(type, num, dataSize) {
		if (type == 1) {
			if (num > 1) {
				num = num - 1
			}else{
				return;
			}
			ready(num,10);
		} else if (type == 2) {

			if (num < dataSize) {
				num = num + 1
				var data={'currentPageNum':num};
				ready(num,10);
			}else{
				return;
			}
		} else if (type == 0) {
			ready(num,10);
		} else {

		}

	}
	
</script>